<template>
	<view>
		<view  v-if="dataList.length>0">
			<view v-for="item in dataList" :key="item.id" class="bg-white my-3 p-2">
			    <view class="d-flex j-sb border-bottom pb-1">
			        <text >{{item.plasmaStationName}}</text>
			        <text>{{item.stationCode}}</text>
			    </view>
			    <view class="d-flex j-sb a-center pt-1">
			        <view>
			          <view class="ln-h2">机器编号：{{item.factoryCode}}</view> 
			          <view class="ln-h2">型号：{{item.type}}</view> 
			          <view class="ln-h2">启用时间：{{item.startTime}}</view> 
			        </view>
			        <view class="text-white bg-success p-1 rounded-circle font-sm" v-if="item.state===1">在用</view>
			        <view class=" bg-light-secondary p-1 rounded-circle  font-sm" v-if="item.state===0">停用</view>
			    </view>
			</view>
		</view>
		
		<view class="d-flex a-center j-center text-light-muted font-sm py-3" v-if="dataList.length>0">
			{{loadtext}}
		</view>
		<no-thing v-else msg="机器为空"></no-thing>
	</view>
</template>

<script>
	import noThing from '@/components/common/no-thing.vue';
	import api from '@/common/api/api.js'
	export default {
		components:{
			noThing
		},
		data() {
			return {
				 /**分页数据 */
				pagination: {
				    currentPage: 1,
				    pageSize: 6,
				    more: 0
				},
				dataList:[],
				loadtext:'没有更多了'
			}
		},
		onLoad(){
			this.init()
		},
		/**搜索提交*/
		onNavigationBarSearchInputConfirmed(e){
			this.keyword = e.text;
			this.init()
		},
		methods: {
			init(){
				this.dataList=[];
				this.pagination.currentPage=1;
				this.getList(false)
			},
			/**上拉刷新*/
			onReachBottom(){
				// 是否已经处于加载状态
				if (this.loadtext !== '上拉加载更多') return;
				// 改变加载状态
				this.loadtext = '加载中...'
				this.pagination.currentPage++
				// 请求数据
				this.getList(false)
			},
			getList(refresh = true, callback = false){
				let self = this;
				let postData={
					...self.pagination,
					keyword:self.keyword
				}
				self.$H.post(api.getMachineList,postData).then(res=>{
					self.dataList = refresh? [...res.content.records]:[...self.dataList,...res.content.records];
					// 恢复加载状态
					self.loadtext = res.content.total > self.pagination.pageSize*self.pagination.currentPage ? '上拉加载更多' : '没有更多了';
				})
			},
		}
	}
</script>

<style>

</style>
